package com.two.screen.water.balance.ui.activity

import android.annotation.SuppressLint
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.gyf.barlibrary.BarHide
import com.gyf.barlibrary.ImmersionBar
import com.two.screen.water.balance.R
import com.two.screen.water.balance.ui.activity.base.BaseActivity
import com.two.screen.water.balance.utils.ARouterUtils
import com.two.screen.water.balance.utils.CommUtils
import com.two.screen.water.balance.widget.dialog.ChooseDateDialog
import com.two.screen.water.balance.widget.dialog.LoadingDialog
import kotlinx.android.synthetic.main.activity_business_report.*

@Route(path = ARouterUtils.BusinessReportActivity)
class BusinessReportActivity : BaseActivity() {
    val TAG = BusinessReportActivity::class.java.simpleName.plus("=>")
    var loadingDialog: LoadingDialog? = null

    var mChooseDateDialog: ChooseDateDialog? = null
    private var mDateBegin: String? = null
    private var mDateEnd: String? = null


    override fun getContentLayout(): Any = R.layout.activity_business_report
    override fun initView(savedInstanceState: Bundle?) {
        ImmersionBar.with(this)
            .hideBar(BarHide.FLAG_HIDE_BAR)
            .init()
    }

    override fun initData() {

    }

    @SuppressLint("CheckResult")
    override fun initListener() {
        mCloseIv.setOnClickListener { finish() }
        initChooseDate()
    }

    @SuppressLint("CheckResult")
    private fun initChooseDate() {
        //筛选日期
        mDateBegin = CommUtils.toYMD(System.currentTimeMillis() / 1000 /*- 8 * 24 * 3600*/)
        mDateEnd = CommUtils.toYMD(System.currentTimeMillis() / 1000)
        mStartTimeTv?.text = mDateBegin
        mEndTimeTv?.text = mDateEnd
        mStartTimeTv?.setOnClickListener { showChooseDate() }
        mEndTimeTv?.setOnClickListener { showChooseDate() }
    }

    private fun showChooseDate() {
        if (mChooseDateDialog == null) mChooseDateDialog = ChooseDateDialog(this)
        mChooseDateDialog?.setOnChooseDateDialogListener(object : ChooseDateDialog.OnChooseDateDialogListener {
            override fun hadSelectedCalendar(mStartDateStr: String, mEndDateStr: String) {
                mStartTimeTv?.text = mStartDateStr
                mEndTimeTv?.text = mEndDateStr
                mDateBegin = mStartDateStr
                mDateEnd = mEndDateStr
            }
        })
        mChooseDateDialog?.show()
    }
}